package com.javabasic.proxy.dynamic_proxy;

import com.javabasic.proxy.static_proxy.CustomTest;
import com.javabasic.proxy.static_proxy.SayInterface;

import java.lang.reflect.Proxy;

/**
 * @Author xiongmin
 * @Description //TODO
 * @Date 2020/5/31 23:31
 * @Version 1.0
 * @TODO  JDK动态代理 Demo
 **/
public class TestDynamicProxy {

    public static void main(String[] args) {
        CustomTest customTest = new CustomTest();
        CuctomTestDynamicProxyHandler cuctomTestDynamicProxyHandler = new CuctomTestDynamicProxyHandler(customTest);

        SayInterface customTestProxy = (SayInterface) Proxy.newProxyInstance(customTest.getClass().getClassLoader(),
                customTest.getClass().getInterfaces(),
                cuctomTestDynamicProxyHandler);

        System.out.println("===================================================================");
        customTestProxy.sayHello();
        String result = customTestProxy.saySomethingWithResult("i am hans");
        System.out.println(result);
        System.out.println("===================================================================");

        System.out.println("Proxy class = "+ customTestProxy.getClass());
        System.out.println("Proxy Parent class = "+customTestProxy.getClass().getSuperclass());
        System.out.println("Proxy Interface class = "+customTestProxy.getClass().getInterfaces());
    }
}
